import { ComputedRef } from 'vue';
/* model */
import { BaseSelectUserMax, BaseSelectUserOptionProvideKey, BaseSelectUserPropsOptions } from '@src/component/common/BaseSelectUser/model'
import { isFalse } from '@src/util/type'
/* store */
import { useBaseSelectUserStoreOptions, useBaseSelectCustomOptions } from '@src/component/common/BaseSelectUser/store'
/* vue */
import { computed, inject } from 'vue'
/* util */
import { isUndefined } from '@src/util/type'

function useBaseSelectUserOptions() {
  
  const { options } = useBaseSelectUserStoreOptions()
  const { CustomOptions } = useBaseSelectCustomOptions()
  
  const getOptionsMax = computed(() => {
    
    if (isUndefined(options.value)) {
      return BaseSelectUserMax
    }
    
    if (isUndefined(options.value?.max)) {
      return BaseSelectUserMax
    }
    
    return Number(options.value?.max)
  })
  
  const showServiceProvider = computed(() => {
    return isUndefined(options.value) ? true : Boolean(options.value?.showServiceProvider)
  })
  
  const showRole = computed(() => {
    return isUndefined(options.value) ? true : Boolean(options.value?.showRole)
  })
  
  const showProjectTeam = computed(() => {
    return isUndefined(options.value) ? false : Boolean(options.value?.showProjectTeam)
  })

  const showDepartment = computed(() => {
    return isUndefined(options.value) ? true : Boolean(options.value?.showDepartment)
  })
  
  const showDelete = computed(() => {
    return isUndefined(options.value) ? true : Boolean(options.value?.showDelete)
  })
  
  const showNoDistribute = computed(() => {
    return isUndefined(options.value) ? true : Boolean(options.value?.showNoDistribute)
  })
  
  const showCancel = computed(() => {
    return isUndefined(options.value) ? true : Boolean(options.value?.showCancel)
  })
  
  const showSpAll = computed(() => {
    return isUndefined(options.value) ? false : Boolean(options.value?.showSpAll)
  })
  
  const isInfiniteOptionsMax = computed(() => {
    return getOptionsMax.value == 0 || getOptionsMax.value == -1
  })
  
  const isShowUser = computed(() => {
    return isUndefined(options.value) ? true : Boolean(options.value?.isShowUser)
  })
  
  const isTag = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.isTag
  })

  const isAuthKey = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.authKey
  })
  
  const isHideUser = computed(() => isFalse(isShowUser.value))
  
  const isShowSearch = computed(() => {
    return isUndefined(options.value) ? true : Boolean(options.value?.isShowSearch)
  })
  
  const isHideSearch = computed(() => isFalse(isShowSearch.value))
  
  const isShowSearchOrganizationUsers = computed(() => {
    return isUndefined(options.value) ? true : Boolean(options.value?.isShowSearchOrganizationUsers)
  })
  
  const isShowSearchServiceProviderUsers = computed(() => {
    return isUndefined(options.value) ? true : Boolean(options.value?.isShowSearchServiceProviderUsers)
  })
  
  const isNeedEmail = computed(() => {
    return isUndefined(options.value) ? false : Boolean(options.value?.isNeedEmail)
  })
  
  const showTagIfSpUser = computed(() => {
    return isUndefined(options.value) ? false : Boolean(options.value?.showTagIfSpUser)
  })
  
  /** 
   * @description 是否为多选状态
  */
  const isMulti = computed(() => {
    return options.value?.max != 1
  })
  
  /** 
   * @description 是否为单选状态
  */
  const isSingle = computed(() => {
    return !isMulti.value
  })
  
  /** 
   * @description 是否严格的遵循父子不互相关联的做法
  */
  const isCheckStrictly = computed(() => {
    return Boolean(options.value?.isCheckStrictly)
  })
  
  // 是否能选择人员
  const isCanChooseUser = computed(() => {
    return options.value?.isCanChooseUser || true
  })
  
  // 是否不能选择人员
  const isNotCanChooseUserUser = computed(() => {
    return isFalse(isCanChooseUser.value)
  })
  
  // 是否能选部门
  const isCanChooseDepartment = computed(() => {
    return Boolean(options.value?.isCanChooseDepartment)
  })
  
  // 是否不能选部门
  const isNotCanChooseDepartment = computed(() => {
    return isFalse(isCanChooseDepartment.value)
  })
  
  // 是否能选角色
  const isCanChooseRole = computed(() => {
    return Boolean(options.value?.isCanChooseRole)
  })
  
  // 是否不能选角色
  const isNotCanChooseRole = computed(() => {
    return isFalse(isCanChooseRole.value)
  })
  
  // 是否能选服务商
  const isCanChooseServiceProvider = computed(() => {
    return Boolean(options.value?.isCanChooseServiceProvider)
  })
  
  // 是否不能选服务商
  const isNotCanChooseServiceProvider = computed(() => {
    return isFalse(isCanChooseServiceProvider.value)
  })
  
  // 是否显示 动态获取 tab
  const isShowDynamic = computed(() => {
    return Boolean(options.value?.isShowDynamic)
  })
  
  // 是否是触发器选人
  const isTrigger = computed(() => {
    return isUndefined(options.value) ? false : Boolean(options.value?.isTrigger)
  })
  
  // 默认显示的 tab
  const currentTabType = computed(() => {
    return (options.value?.currentTabType)
  })
  
  // 已选择数据
  const selected = computed(() => {
    return (options.value?.selected)
  })
  
  // 是否为部门单选
  const isDepartmentSingle = computed(() => {
    return isHideUser.value && isSingle.value;
  })
  
  const fetchDepartmentList = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.fetchDepartmentList
  })
  
  const fetchDepartmentUserList = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.fetchDepartmentUserList
  })
  
  const fetchSearchUserList = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.fetchSearchUserList
  })
  
  const fetchProjectTeamList = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.fetchProjectTeamList
  })

  const fetchProjectTeamUserList = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.fetchProjectTeamUserList
  })
  
  const fetchSearchMoreUserList = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.fetchSearchMoreUserList
  })
  
  const renderDynamicContent = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.renderDynamicContent
  })
  
  const isScreenSelect = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.isScreenSelect
  })
  
  const isRenderFilterContent = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.isRenderFilterContent
  })
  
  const isOnlyShowBusinessServiceCloudRole = computed(() => {
    return isUndefined(options.value) ? false : Boolean(options.value?.isOnlyShowBusinessServiceCloudRole)
  })
  
  const renderFilterContent = computed(() => {
    return isUndefined(options.value) ? undefined : options.value?.renderFilterContent
  })
  
  const isHideNullProvider = computed(() => {
    return isUndefined(options.value?.hideNullProvider) ? false : Boolean(options.value?.hideNullProvider)
  })
  
  const asyncConfirm = computed(() => {
    return isUndefined(options.value?.asyncConfirm) ? undefined : options.value?.asyncConfirm
  })
  
  return {
    CustomOptions,
    
    getOptionsMax,
    
    isShowUser,
    isHideUser,
    isHideSearch,
    isInfiniteOptionsMax,
    isMulti,
    isSingle,
    isCheckStrictly,
    isCanChooseUser,
    isNotCanChooseUserUser,
    isCanChooseDepartment,
    isNotCanChooseDepartment,
    isCanChooseRole,
    isNotCanChooseRole,
    isCanChooseServiceProvider,
    isNotCanChooseServiceProvider,
    isTag,
    isAuthKey,
    isNeedEmail,
    isShowDynamic,
    showTagIfSpUser,
    currentTabType,
    selected,
    isDepartmentSingle,
    
    isShowSearch,
    isShowSearchOrganizationUsers,
    isShowSearchServiceProviderUsers,
    isOnlyShowBusinessServiceCloudRole,
    
    isTrigger,
    
    showRole,
    showProjectTeam,
    showDepartment,
    showServiceProvider,
    showDelete,
    showNoDistribute,
    showCancel,
    showSpAll,
    
    fetchDepartmentList,
    fetchDepartmentUserList,
    fetchSearchUserList,
    fetchProjectTeamList,
    fetchProjectTeamUserList,
    fetchSearchMoreUserList,
    
    renderDynamicContent,
    isScreenSelect,
    isRenderFilterContent,
    renderFilterContent,
    isHideNullProvider,
    
    asyncConfirm
  }
}

export {
  useBaseSelectUserOptions
}
